<?php

/**
 * RecommenderForm class.
 * RecommenderForm is the data structure for keeping
 * recommendation input data. It is used by the 'index' action of 'RecommenderController'.
 */
class RecommenderForm extends CFormModel
{
	public $gender;
	public $age;
	public $weight;
	public $height;
	public $state;
	public $interest;

	/**
	 * Declares the validation rules.
	 * The rules state that username and password are required,
	 * and password needs to be authenticated.
	 */
	public function rules()
	{
		return array(
			array('gender, age, weight, height, state, interest', 'required'),
			array('age, weight, height', 'numerical'),
			array('age', 'length', 'min'=>1, 'max'=>3),
			array('weight', 'length', 'min'=>1, 'max'=>3),
			array('height', 'length', 'min'=>2, 'max'=>3),
			
		);
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'gender'=>'Sexo',
			'age'=>'Edad',
			'weight'=>'Peso (kg)',
			'height'=>'Altura (cm)',
			'state'=>'Estado físico',
			'interest'=>'Interés'
		);
	}
	
	private function _getDict($model)
	{
		$all = $model->findAll();
		$dict = array();
		foreach ($all as $item) {
			$dict[$item->id] = $item->label;
		}		
		return $dict;		
	}
	
	public function getStatesDict()
	{
		return $this->_getDict(State::model());
	}

	public function getInterestDict()
	{
		return $this->_getDict(Interest::model());
	}
	
}
